package com.ly.common.running.start;

import com.ly.common.running.config.DatabaseType;
import org.slf4j.MDC;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.core.env.PropertyResolver;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RunningLoad implements ApplicationRunner {
    @Resource
    PropertyResolver propertyResolver;
    @Resource
    DatabaseType databaseType;

    public void run(ApplicationArguments args) throws Exception {
        System.out.println(this.transColor("*****************************************"));
        System.out.println(this.transColor("*   *   *   *   *   *   *   *   *   *   *"));
        System.out.println(this.transColor("**************工程启动成功！****************"));
        System.out.println(this.transColor("*   *   *   *   *   *   *   *   *   *   *"));
        System.out.println(this.transColor("*****************************************"));
        System.out.println(this.transColor(this.getProperties()));
    }

    private String getProperties() {
        String appName = propertyResolver.getProperty("spring.application.name");
        String active = propertyResolver.getProperty("spring.profiles.active");
        String server = propertyResolver.getProperty("server.port");
        StringBuffer sb = new StringBuffer();
        sb.append("activeProfiles=").append(active).append(",");
        sb.append("appName=").append(appName).append(",");
        sb.append("serverPort=").append(server).append(",");
        String databaseValue = databaseType.getType();
        sb.append("databseType=").append(databaseValue).append(",");
        return sb.toString();
    }

    private String transColor(String str) {
        return AnsiOutput.toString(new Object[]{AnsiColor.BRIGHT_BLUE, str});
    }
}
